package com.itown.expo.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.springframework.web.servlet.ModelAndView;

import webframe.common.helper.ControllerHelper;

import com.itown.expo.controller.base.MyBaseCommandController;
import com.itown.expo.model.RecordCodes;

public class RecordCodePublishController extends MyBaseCommandController {
	private static Order[] orders = new Order[] { Order.asc("id") };

	@Override
	protected ModelAndView handleInner(HttpServletRequest request,
			HttpServletResponse response, Object command) {
		RecordCodes ccode = (RecordCodes) command;

		DetachedCriteria criteria = DetachedCriteria
				.forClass(RecordCodes.class);

		ControllerHelper.addEqualRestrictions(criteria, "id", ccode.getId());
		ControllerHelper.addLikeRestrictions(criteria, "name", ccode.getName());
		ControllerHelper.addLikeRestrictions(criteria, "code", ccode.getCode());

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("appPrefix", getAppPrefix());
		map.put("page", ControllerHelper.queryPagination(request, orders,
				criteria));
		map.put("ccode", ccode);
		return new ModelAndView("RecordCodesPublish.jsp", "map", map);
	}

}
